<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<jsp:include page="/includes/top.jsp"></jsp:include>
<div class="page-header">
	<h1></h1>
</div>
<!-- /.page-header -->
<div class="row">
	<div class="col-xs-12">
		<form class="form-horizontal" id="taskForm">
			<div style="display: none">
				<input name="task.taskId" type="hidden" value="${task.taskId}"/>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">项目名称</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<s:select cssClass="form-control" name="task.taskProject" id="project"
						list="#plist " listValue="projectName" listKey="projectId"
						value="task.taskProject"></s:select>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">任务名称</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<input type="text" class="form-control" name="task.taskName"
							placeholder="任务名称" value="${task.taskName}"/>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">开始时间</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<div class="input-group">
							<input type="text" name="task.taskStartDate" id="taskStartDate"
								value="${task.taskStartDate}"
								class="form-control date-picker" /> <span
								class="input-group-addon"> <i
								class="icon-calendar bigger-110"></i>
							</span>
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">结束时间</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<div class="input-group">
							<input type="text" name="task.taskEndTime" id="taskEndTime"
								value="${task.taskEndTime}"
								class="form-control date-picker" /> <span
								class="input-group-addon"> <i
								class="icon-calendar bigger-110"></i>
							</span>
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">任务描述</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<textarea class="form-control" name="task.taskDescription"
							placeholder="任务描述" rows="6">${task.taskDescription}</textarea>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">任务所有者</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<s:select cssClass="form-control" name="task.taskOwner" id="users"
						list="#ulist " listValue="sysUserinfo.userinfoTruename" listKey="userId"
						value="task.taskOwner"></s:select>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">父任务</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<s:select cssClass="form-control" name="task.taskParent" id="tasks"
						list="#mlist " listValue="taskName" listKey="taskId" headerKey="0"
						headerValue="请选择父任务" value="task.taskParent"></s:select>	
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">已进行小时数</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<input type="text" class="form-control" value="${task.taskHoursWorked}"
							name="task.taskHoursWorked" placeholder="已进行小时数" />
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">完成百分比</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<input type="text" class="form-control" id="tpc" value="${task.taskPercentComplete}"
							name="task.taskPercentComplete" placeholder="完成百分比" />
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">任务类型</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<s:select cssClass="form-control" name="task.taskType"
						list="#tlist " listValue="taskTypeName"
						listKey="taskTypeId" value="task.taskType"></s:select>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">状态</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<s:select cssClass="form-control" name="task.taskStatus"
						list="#slist " listValue="taskStatusName"
						listKey="taskStatusId" value="task.taskStatus"></s:select>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">优先级</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<s:select cssClass="form-control" name="task.taskPriority"
						list="#ilist " listValue="taskPriorityName"
						listKey="taskPriorityId" value="task.taskPriority"></s:select>
					</div>
				</div>
			</div>
			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-info" id="save" type="button">
						<i class="icon-ok"></i> 保存
					</button>

					&nbsp; &nbsp; &nbsp;
					<button class="btn" type="reset" id="back">
						<i class="icon-undo"></i> 取消
					</button>
				</div>
			</div>
		</form>
	</div>
	<!-- /.col -->
</div>
<jsp:include page="/includes/bottom.jsp"></jsp:include>

<script type="text/javascript">
	var tid = getQueryString("task.taskId");

	//添加
	function savafrom(url) {
		$("#save").click(function() {
			$("#taskForm").bootstrapValidator("validate");
			if ($("#taskForm").data("bootstrapValidator").isValid()) {
				var dataMap = $("#taskForm").serializeArray();
				$.ajax({
					type : "post",
					url : url,
					data : dataMap,
					dataType : "json",
					success : function(data) {
						window.open("Task/tasklist.jsp?m=" + mid, "_self");
					}
				});
			}
		});
	}

	$(document).ready(function() {
		$('.date-picker').datetimepicker({
			lang : 'ch',
			format : 'Y-m-d H:m:s'
		}).next().on("click", function() {
			$(this).prev().focus();
		});

		if (tid != null && tid != "") {
			savafrom("edittask");
		} else {
			savafrom("addtask");
		}
		if($("#tpc").val()=="")$("#tpc").val(0);
		$("#project").change(function() {
			setselectval("tasks","taskall","taskId","taskName",{proid:$(this).val()});	
			setselectval("users","userall","userId","userinfoTruename",{proid:$(this).val()});				
		});
		$("#back").click(function() {
			window.history.back();
		});

		validator();
		$("#taskStartDate").on("change show", function() {
            $("#taskForm").bootstrapValidator("revalidateField", "task.taskStartDate");
        });
        $("#taskEndTime").on("change show", function() {
            $("#taskForm").bootstrapValidator("revalidateField", "task.taskEndTime");
        });
	});
	
	function validator() {
		$("#taskForm").bootstrapValidator({
			feedbackIcons : {
				valid : 'icon-ok-sign',
				invalid : 'icon-remove-sign',
				validating : 'icon-refresh'
			},
			fields : {
				'task.taskName' : {
					validators : {
						notEmpty : {
							message : '任务名称,不能是空的!'
						}
					}
				},
				'task.taskStartDate' : {
					validators : {
						notEmpty : {
							message : '开始日期，不能为空！'
						}
					}
				},
				'task.taskEndTime' : {
					validators : {
						notEmpty : {
							message : '结束日期，不能为空！'
						}
					}
				},
				'task.taskHoursWorked' : {
					validators : {
						regexp: {
	                        regexp: /^[0-9_\.]+$/,
	                        message: '只能输入数字'
	                    }
					}
				},
				'task.taskPercentComplete' : {
					validators : {
						regexp: {
	                        regexp: /^[0-9_\.]+$/,
	                        message: '只能输入数字'
	                    },
						greaterThan : {
							value : 0,
							inclusive : true,
							message : '最小值0'
						},
						lessThan : {
							value : 100,
							inclusive : true,
							message : '最大值100'
						}
					}
				}
			}
		});
	}
</script>
